home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD 2.1 / Amiga Developer CD v2.1.iso / Reference / DevCon / Milan_1991 / Devcon91.2 / Bullet / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-09-01  |  3.9 KB  |  152 lines

  1. /*
  2. **    $Id$
  3. **
  4. **      printer support for prtface
  5. **
  6. **      (C) Copyright 1991 Robert R. Burns
  7. **          All Rights Reserved
  8. */
  9. #ifdef   DEBUG
  10. #define  D(a)    printf a
  11. #else
  12. #define  D(a)
  13. #endif
  14.  
  15. #include <exec/types.h>
  16. #include <exec/ports.h>
  17. #include <exec/tasks.h>
  18. #include <graphics/rastport.h>
  19. #include <graphics/text.h>
  20. #include <devices/prtbase.h>
  21. #include <devices/printer.h>
  22.  
  23. #include <clib/exec_protos.h>
  24. #include <clib/graphics_protos.h>
  25. #include <pragmas/exec_pragmas.h>
  26. #include <pragmas/graphics_pragmas.h>
  27.  
  28. extern struct Library *SysBase;
  29. extern struct Library *GfxBase;
  30.  
  31. struct MsgPort PrinterPort;
  32. struct IODRPReq PrinterIO;
  33. struct RastPort PrinterRP;
  34. struct BitMap PrinterBM;
  35. struct ColorFontColors PrinterCM;
  36. UWORD ColorTable[2] = {
  37.     0x0fff, 0x0000
  38. };
  39. WORD MaxX, MaxY, DPIX, DPIY;
  40.  
  41. void
  42. ClosePrinter()
  43. {
  44.     if (PrinterBM.Planes[0]) {
  45.     D(("FreeRaster(,%ld, %ld)\n", MaxX, MaxY));
  46.     FreeRaster(PrinterBM.Planes[0], MaxX, MaxY);
  47.     }
  48.     if (PrinterIO.io_Device) {
  49.     D(("CloseDevice printer.device\n"));
  50.     CloseDevice(&PrinterIO);
  51.     }
  52.     D(("ClosePrinter done.\n"));
  53. }
  54.  
  55. int
  56. OpenPrinter()
  57. {
  58.     struct PrinterExtendedData *ped;
  59.     WORD d;                /* printer density */
  60.     int result;
  61.  
  62.     /* initialize PrinterPort */
  63.     PrinterPort.mp_Flags = PA_SIGNAL;
  64.     PrinterPort.mp_SigBit = SIGB_SINGLE;
  65.     PrinterPort.mp_SigTask = FindTask(0);
  66.     NewList(&PrinterPort.mp_MsgList);
  67.  
  68.     /* initialize PrinterRP (that can be done w/o knowing size) */
  69.     InitBitMap(&PrinterBM, 1, 1000, 1000);
  70.     PrinterBM.Planes[0] = 0;
  71.     InitRastPort(&PrinterRP);
  72.     PrinterRP.BitMap = &PrinterBM;
  73.  
  74.     PrinterCM.cfc_Reserved = 0;
  75.     PrinterCM.cfc_Count = 2;
  76.     PrinterCM.cfc_ColorTable = ColorTable;
  77.  
  78.     /* initialize PrinterIO */
  79.     PrinterIO.io_Message.mn_ReplyPort = &PrinterPort;
  80.     if (result = OpenDevice("printer.device", 0, &PrinterIO, 0)) {
  81.     D(("OpenDevice of printer.device failed %ld\n", result));
  82.     PrinterIO.io_Device = 0;
  83.     return (result);
  84.     }
  85.  
  86.     /* get printer dimensions */
  87.     PrinterIO.io_Command = PRD_DUMPRPORT;
  88.     PrinterIO.io_RastPort = &PrinterRP;
  89.     PrinterIO.io_ColorMap = (struct ColorMap *) & PrinterCM;
  90.     PrinterIO.io_Modes = 0;
  91.     PrinterIO.io_SrcX = PrinterIO.io_SrcY = 0;
  92.     PrinterIO.io_SrcWidth = PrinterIO.io_SrcHeight = 1000;
  93.     PrinterIO.io_DestCols = PrinterIO.io_DestRows = 0;
  94.     for (d = SPECIAL_DENSITY7; d >= 0; d -= SPECIAL_DENSITY1) {
  95.     PrinterIO.io_Special = SPECIAL_NOPRINT | d;
  96.     if (result = DoIO(&PrinterIO)) {
  97.         D(("DoIO NOPRINT DENSITY %ld failed %ld\n", d >> 8, result));
  98.     }
  99.     else
  100.         goto gotDimensions;
  101.     }
  102.     /* failed all densities */
  103.     D(("failed all densities\n"));
  104.     return (-1);
  105.  
  106. gotDimensions:
  107.     PrinterIO.io_Special &= ~SPECIAL_NOPRINT;
  108. #if 0
  109.     PrinterIO.io_Special |= SPECIAL_TRUSTME;
  110. #endif
  111.     D(("density %ld dimensions %ld x %ld\n", d >> 8,
  112.             PrinterIO.io_DestCols, PrinterIO.io_DestRows));
  113.     ped = &((struct PrinterData *) PrinterIO.io_Device)->pd_SegmentData->ps_PED;
  114.     DPIX = ped->ped_XDotsInch;
  115.     DPIY = ped->ped_XDotsInch;
  116.     D(("max dots %ld %ld, DPI %ld %ld\n", ped->ped_MaxXDots, ped->ped_MaxYDots,
  117.             DPIX, DPIY));
  118. #if 0
  119.     PrinterIO.io_SrcWidth = MaxX = ped->ped_MaxXDots;
  120.     PrinterIO.io_SrcHeight = MaxY = ped->ped_MaxYDots;
  121. #else
  122.     PrinterIO.io_SrcWidth = MaxX = PrinterIO.io_DestCols;
  123.     PrinterIO.io_SrcHeight = MaxY = PrinterIO.io_DestRows;
  124. #endif
  125.     InitBitMap(&PrinterBM, 1, MaxX, MaxY);
  126.     PrinterBM.Planes[0] = AllocRaster(MaxX, MaxY);
  127.     if (!PrinterBM.Planes[0]) {
  128.     D(("AllocRaster failure\n"));
  129.     return (-1);
  130.     }
  131.     D(("OpenPrinter done.\n"));
  132.     return (0);
  133. }
  134.  
  135. int
  136. Print()
  137. {
  138.     int result;
  139.  
  140.     D(("Print...\n"));
  141.     if (result = DoIO(&PrinterIO)) {
  142.     D(("Print error %ld\n", PrinterIO.io_Error));
  143.     return (result);
  144.     }
  145.     CloseDevice(&PrinterIO);
  146.     if (result = OpenDevice("printer.device", 0, &PrinterIO, 0)) {
  147.     D(("OpenDevice of printer.device failed %ld\n", result));
  148.     PrinterIO.io_Device = 0;
  149.     return (result);
  150.     }
  151. }
  152.